package com.zzk.lanouhn.myapplication1.adapters;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;

import com.squareup.picasso.Picasso;
import com.zzk.lanouhn.myapplication1.R;
import com.zzk.lanouhn.myapplication1.modles.PublishArticles;

/**
 * Created by lanouhn on 16/9/5.
 */
public class MyGridViewPublishGoodAdapter extends BaseAdapter{
    private Context context;
    private PublishArticles publishArticles;

    public MyGridViewPublishGoodAdapter(Context context, PublishArticles publishArticles) {
        this.context = context;
        this.publishArticles = publishArticles;
    }

    @Override
    public int getCount() {
        return publishArticles.getData().getPost().size();
    }

    @Override
    public Object getItem(int position) {
        return publishArticles.getData().getPost().get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder=null;
        if (convertView == null) {
            holder=new ViewHolder();
            convertView = View.inflate(context, R.layout.item_mygridview1, null);
            holder.iv_pic = (ImageView) convertView.findViewById(R.id.iv_pic_gridview1);
            convertView.setTag(holder);
        } else {
            holder= (ViewHolder) convertView.getTag();
        }
        Picasso.with(context).load(publishArticles.getData().getPost().get(position).getMini_pic_url()).into(holder.iv_pic);

        return convertView;
    }

    public class ViewHolder{
        private ImageView iv_pic;
    }
}
